<?php

namespace App\Admin\Models;

use App\Common\Services\Common;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class AdminUser extends Model
{
    protected $table = 'admin_user';
    public $timestamps = false;
    protected $primaryKey = 'id';
    protected $guarded = ['_token'];

    /**
     *获取列表 
     */
    public static function getList(Request $request)
    {
        $query = self::where(['type'=>2])->orderBy('create_at', 'desc');
        
        $status = $request->status ?? 0;
        $isgetall = intval($request->isgetall) ?? 0;
        if (in_array($status, [1, 2])) {
            $query->where('status', $status);
        }
        $real_name = $request->real_name;
        if ($real_name != '') {
            $query->where('real_name', 'like', '%' . $real_name . '%');
        }
        if ($isgetall == 0) {
            $limit = $request->limit ?? 10;
            $list = $query->paginate($limit)->toArray();
            return Common::paginateDataToArray($list);
        } else {
            $list = $query->get()->toArray();
            return ['list' => $list];
        }
    }
}